import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-16
 * Time: 2:10
 */
//https://leetcode.cn/problems/longest-substring-without-repeating-characters/
public class Test {
    public static int lengthOfLongestSubstring(String s) {
        HashSet set=new HashSet();
        int max=0;
        int n=0;
        int len=s.length();
        for(int p1=0,p2=0;p2<len;p2++){
            while(set.contains(s.charAt(p2))){
                set.remove(s.charAt(p1++));
                n--;
            }
            set.add(s.charAt(p2));
            n++;
            max=Math.max(max,n);
        }
        return max;
    }
    public static void main(String[] args) {
        String str="abcabcbb";
        System.out.println(lengthOfLongestSubstring(str));

    }
}
